package com.desire.test;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

public class _16_遍历目录 {
    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources");
        if (file.exists() && file.isDirectory()) {
            //遍历目录
            for (File listFile : Objects.requireNonNull(file.listFiles())) {
                System.out.println(listFile.getName());
                System.out.println(listFile.getAbsolutePath());
                System.out.println(listFile.getAbsoluteFile());
                System.out.println(listFile.isFile());
                System.out.println(listFile.isHidden());
                System.out.println(listFile.isDirectory());
                System.out.println(listFile.getPath());
                System.out.println(listFile.getParent());
                System.out.println("-".repeat(50));
            }
        }


        //创建文件
        File file1 = new File("C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\test.txt");
        System.out.println(file1.createNewFile());

        //删除文件
        //if (file1.exists()) file1.delete();

        System.out.println(file1.length());
        
        //查询文件最后修改的时间
        System.out.printf("%1$tF %1$tT \n", file1.lastModified());
    }
}
